package com.fy.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 江迪
 */
@Component
@Slf4j
public class ClearSecurityContextInterceptor implements HandlerInterceptor {

    //重写afterCompletion方法(当handle完全执行完之后执行)
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

        SecurityContextHolder.clearContext();

        log.info("清除SecurityContext上下文信息");
    }
}
